package com.gao.modules.role.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gao.base.Result;
import com.gao.modules.role.dto.SysRoleDto;
import com.gao.modules.role.pojo.SysRole;
import com.gao.modules.role.service.SysRoleService;
import com.gao.modules.role.vo.SysRoleVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/role")
public class RoleController {

    @Autowired
    private SysRoleService sysRoleService;

    @ResponseBody
    @RequestMapping("/test")
    public String test(){
        return "123";
    }

    //todo 加入角色名称的搜索条件  注意去除空格
    @ResponseBody
    @GetMapping("/queryAllRole")
    public IPage<SysRoleVo> queryAllRole(@RequestParam(name = "pageNo") Integer pageNo,
                                         @RequestParam(name = "pageSize") Integer pageSize){
        Page page = new Page(pageNo,pageSize);
        return sysRoleService.queryAllRole(page);
    }

    @ResponseBody
    @PostMapping("/insert")
    public Result insert(@RequestBody SysRoleDto sysRoleDto){
        SysRole sysRole = new SysRole();
        BeanUtils.copyProperties(sysRoleDto,sysRole);
        return sysRoleService.insertRole(sysRole);
    }

    @ResponseBody
    @PostMapping("/update")
    public Result update(@RequestBody SysRoleDto sysRoleDto){
        SysRole sysRole = new SysRole();
        BeanUtils.copyProperties(sysRoleDto,sysRole);
        return sysRoleService.updateRole(sysRole);
    }

    @ResponseBody
    @DeleteMapping("/delete")
    public Result delete(@RequestBody String roleId){
        return sysRoleService.deleteRole(roleId);

    }




}
